package cn.getech.data.development.controller.api;

import cn.getech.data.development.api.JobRunHistoryApi;
import cn.getech.data.development.entity.JobRunHistory;
import cn.getech.data.development.service.JobRunHistoryService;
import cn.hutool.core.collection.CollectionUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @ClassName JobNodeInfoApiController
 * @Description TODO
 * @Author Getech
 * @Date 2020/12/24 11:46
 */
@RestController
public class JobRunHistoryApiController implements JobRunHistoryApi {

    @Autowired
    private JobRunHistoryService jobRunHistoryService;

    @Override
    public JobRunHistory getJobRunHistoryOne(JobRunHistory jobRunHistory) {
        if(null != jobRunHistory){
            QueryWrapper<JobRunHistory> jobRunHistoryQueryWrapper = new QueryWrapper<>();
            jobRunHistoryQueryWrapper.eq(StringUtils.isNotEmpty(jobRunHistory.getOozieJobId()),"oozie_job_id",jobRunHistory.getOozieJobId());
            jobRunHistoryQueryWrapper.eq(null != jobRunHistory.getJobInfoId(),"job_info_id",jobRunHistory.getJobInfoId());
            List<JobRunHistory> list = jobRunHistoryService.list(jobRunHistoryQueryWrapper);
            if(CollectionUtil.isNotEmpty(list)){
                return list.get(0);
            }
        }
        return null;
    }

    @Override
    public void insert(JobRunHistory jobRunHistory) {
        jobRunHistoryService.save(jobRunHistory);
    }

    @Override
    public void saveOrUpdate2(JobRunHistory jobRunHistory) {
        jobRunHistoryService.saveOrUpdate2(jobRunHistory);
    }

    @Override
    public List<JobRunHistory> selectListByDepOozieId(String oozieId) {
        return jobRunHistoryService.list(new QueryWrapper<JobRunHistory>().eq("dep_oozie_job_id",oozieId));
    }

    @Override
    public List<JobRunHistory> selectAllRunningList() {
        return jobRunHistoryService.selectAllRunningList();
    }
}
